import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaTop, WeaRightMenu, WeaSlideModal, WeaNewScroll, WeaTab, WeaAlertPage, WeaLocaleProvider, WeaTools,WeaDialog } from 'ecCom';
import { toJS } from "mobx"
import TabDiscuss from '../common/TabDiscuss'
import TaskList from './TaskList';
import TaskCard from './TaskCard';
import ProjectInfo from '../common/projectInfo'
import ProjectSub from '../common/projectSub'
import AddProject from '../dialog/addProjectDialog'
import ProjectShare from '../common/sharePage'
import StageList from '../common/stageList';
import ProjectStastics from '../common/ProjectStastics'
import ResourcePage from '../common/resourcePage';
import App from '../App';
import BoardApp from "./BoardApp";
import { Spin, Button, Modal } from 'antd';
import SaveTemplateDialog from "../dialog/SaveTemplateDialog";
import ProjectLogDialog from "../dialog/modifyLogDialog"
import ProjectFieldLogDialog from '../dialog/projectFieldLogDialog';
import ProjectFieldDetailLogDialog from '../dialog/ProjectFieldDetailLogDialog';
import taskBatchEditDialogStore from '../../stores/taskBatchEditDialogStore';
import TaskImport from '../import/TaskImport'

const getLabel = WeaLocaleProvider.getLabel;
@inject('prjImportStore')
@observer
export default class ProjectBoardBase extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            workPlanVisible: false,
            importVisible:false
        }
    }
    render() {
        let _this = this;
        const { projectBoardStore } = this.props;
        const { prjTaskCardStore,tabsStore,prjCardStore,prjid} = projectBoardStore;
        const account = WeaTools.ls.getJSONObj('theme-account');
        let dialogHeight = window.innerHeight - 150;
        if (dialogHeight > 600) dialogHeight = 600;
        if (tabsStore.verified) {
            let viewObj = function (key) {
                const tabDatas1 = toJS(tabsStore.tabDatas);
                if (tabDatas1) {
                    for (let i = 0; i < tabDatas1.length; i++) {
                        if (tabDatas1[i].shortname == "taskboard" && tabDatas1[i].key == key) {   //任务看板
                            // return <App key={projectBoardStore.refelsh} boardStore={projectBoardStore} />
                            return <BoardApp ecId={`${this && this.props && this.props.ecId || ''}_BoardApp@45nkdb`}  key={projectBoardStore.refelsh+''+projectBoardStore.prjid}  boardStore={projectBoardStore}></BoardApp>
                        } else if (tabDatas1[i].shortname == "prjinfo" && tabDatas1[i].key == key) {//项目卡片
                            return <div>
                            <ProjectInfo ecId={`${this && this.props && this.props.ecId || ''}_ProjectInfo@r4wvt9`} formStore={prjCardStore} />
                            <ProjectLogDialog ecId={`${this && this.props && this.props.ecId || ''}_ProjectLogDialog@7zpcmh`} ref="projectLogDialog" title={getLabel('33782','项目日志') } tableStore={prjCardStore.prjLogTableStore} store={prjCardStore} />
                            <ProjectFieldLogDialog ecId={`${this && this.props && this.props.ecId || ''}_ProjectFieldLogDialog@rjfhnw`} title={getLabel('82274','字段日志') } tableStore={prjCardStore.prjFieldLogTableStore} store={prjCardStore} />
                            <ProjectFieldDetailLogDialog ecId={`${this && this.props && this.props.ecId || ''}_ProjectFieldDetailLogDialog@pcevom`} title={getLabel('82274','字段日志')+"-"+prjCardStore.fieldname } tableStore={prjCardStore.prjFieldDetailLogTableStore} store={prjCardStore} />
                            <SaveTemplateDialog ecId={`${this && this.props && this.props.ecId || ''}_SaveTemplateDialog@a9ac2g`} prjCardStore={prjCardStore}/>
                            {
                                    prjCardStore.isreload && window.weaWorkplan && window.weaWorkplan.com && window.weaWorkplan.com.WorkPlanCreate &&
                                    (<window.weaWorkplan.com.WorkPlanCreate ecId={`${this && this.props && this.props.ecId || ''}_WorkPlanCreate@ycjdlt`}
                                        type={"create"}//新建为'create',查看为'preview',编辑edit,共享share
                                        visible={_this.state.workPlanVisible}//显隐受控
                                        doClose={() => { _this.setWorkPlanVisible(false); }}//关闭回调
                                        onlyClose={() => { _this.setWorkPlanVisible(false) }}//关闭回调,只做关闭操作
                                        workPlanId={""} //日程id，1查看日程时用到
                                        createConditionParams={[]}//创建的默认值日期和时间,没有传[]
                                        activeKey={""} //查看页面显示的面板1是基本信息，7是相关交流
                                        //changeTab={(key) => { }}//查看页面切换面板的回调
                                        selectUser={account && account.userid}//新建日程的创建人id
                                        workPlanTypeOptions={"2"}//客户模块的新建日程，普通新建传'',客户新建传3
                                        crmIDs={[]}//通过客户模块新建日程，并自动带出相关客户,[{'id':'','name':''}]
                                        projectid={prjid}
                                        description={""}//客户模块需求，支持新建时传入的'基本信息-内容'
                                    />)
                                }
                            </div>
                        } else if (tabDatas1[i].shortname == "tasklist" && tabDatas1[i].key == key) {//任务列表
                            return <div style={{height:"100%"}}>
                                <TaskList ecId={`${this && this.props && this.props.ecId || ''}_TaskList@8oulej`} contentStore={prjCardStore} boardStore={projectBoardStore} taskBatchEditDialogStore={taskBatchEditDialogStore}/>
                                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@yxh592`}
                                    title={getLabel(383858,"任务导入")}
                                    visible={_this.state.importVisible}
                                    icon='icon-coms-project'
                                    iconBgcolor='#217346'
                                    onCancel={() => { _this.doClose() }}
                                    style={{ width: 870, height: dialogHeight }}
                                    buttons={_this.getDialogTopButtons()}
                                >
                                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@fhr2jm`} datas={_this.getDialogRightMenu()}>
                                        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@0aa856`} height={dialogHeight} ref="scrollBar">
                                            <TaskImport ecId={`${this && this.props && this.props.ecId || ''}_TaskImport@rf5q4c`}  key={new Date().getTime()} />
                                        </WeaNewScroll>
                                    </WeaRightMenu>
                                </WeaDialog >
                            </div>
                        } else if (tabDatas1[i].shortname == "childprj" && tabDatas1[i].key == key) {//子项目
                            return [<ProjectSub ecId={`${this && this.props && this.props.ecId || ''}_ProjectSub@xy05wc`} contentStore={prjCardStore} />, <AddProject ecId={`${this && this.props && this.props.ecId || ''}_AddProject@fl6gmz`} contentStore={prjCardStore} isreflesh={true} />]
                        } else if (tabDatas1[i].shortname == "prjdiscuss" && tabDatas1[i].key == key) {//相关交流
                            return <TabDiscuss ecId={`${this && this.props && this.props.ecId || ''}_TabDiscuss@68u89r`} contentStore={prjCardStore} sortid={prjid}/>
                        } else if (tabDatas1[i].shortname == "prjshare" && tabDatas1[i].key == key) {//共享设置
                            return <ProjectShare ecId={`${this && this.props && this.props.ecId || ''}_ProjectShare@dl003a`} contentStore={prjCardStore} shareCondition={prjCardStore.shareStore.shareCondition} title={getLabel(83816, "添加项目共享")} />
                        } else if (tabDatas1[i].shortname == "stareport" && tabDatas1[i].key == key) {//统计报告
                            return <ProjectStastics ecId={`${this && this.props && this.props.ecId || ''}_ProjectStastics@5rozci`} contentStore={prjCardStore} statkey={prjCardStore.statkey} />
                        } else if (tabDatas1[i].shortname == "stageset" && tabDatas1[i].key == key) {  //阶段
                            return <StageList ecId={`${this && this.props && this.props.ecId || ''}_StageList@ucz5mq`} ref="StageList" contentStore={prjCardStore} />
                        } else if (tabDatas1[i].shortname == "resources" && tabDatas1[i].key == key) {  //相关资源
                            return <ResourcePage ecId={`${this && this.props && this.props.ecId || ''}_ResourcePage@rtjzim`} contentStore={prjCardStore} />
                        } else if (tabDatas1[i].shortname == "gantt" && tabDatas1[i].key == key) {//甘特图及其他
                            return tabDatas1[i].linkurl;
                        } else if (tabDatas1[i].shortname == "" && tabDatas1[i].key == key) {
                            if (tabDatas1[i].linkurl.indexOf("noright") > -1) {
                                return <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@od36db`} >
                                    <div style={{ color: '#000' }}>
                                        {getLabel(2012, "对不起，您暂时没有权限！")}
                                    </div>
                                </WeaAlertPage>
                            } else {
                                return tabDatas1[i].linkurl;
                            }
                        }
                    }
                }
            }(projectBoardStore.tabsStore.activeKey);

            return (
                <div onClick={() => projectBoardStore.showSlideModal(false)}>
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@qmzhqa`}
                        datas={this.getRightMenu()}
                        onClick={this.onRightMenuClick.bind(this)}
                    >
                        <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@7evjyu`}
                            title={projectBoardStore.title}
                            icon={<i className='icon-coms-project' />}
                            iconBgcolor='#217346'
                            showDropIcon={true}
                            buttons={this.getButtons()}
                            onDropMenuClick={this.onRightMenuClick.bind(this)}
                        >
                            <div style={{ height: "100%", overflow: "hidden" }}>
                                <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@lshlzj`}
                                    datas={toJS(projectBoardStore.tabsStore.tabDatas)}
                                    keyParam="viewcondition"  //主键
                                    countParam="groupid" //数量
                                    selectedKey={projectBoardStore.tabsStore.activeKey}
                                    onChange={this.onChange}
                                />
                                <div style={{ height: "calc(100% - 47px)" }}  >
                                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@6tnl0u`} height={"100%"} >
                                        {
                                            typeof viewObj === "object" ? viewObj :
                                                <iframe src={viewObj} id="prjtabiframe" name="prjtabiframe" className="flowFrame" frameborder="0" width="100%" height="100%" />
                                        }
                                    </WeaNewScroll>
                                </div>
                            </div>
                        </WeaTop>
                        <div onClick={(e) => e.stopPropagation()} className={"Prj-WeaSlideModal"}>
                            <WeaSlideModal ecId={`${this && this.props && this.props.ecId || ''}_WeaSlideModal@6qfs3s`} visible={projectBoardStore.SlideModalVisible}
                                top={"0px"}
                                width={"800px"}
                                height={"100%"}
                                direction={'right'}
                                measure={''}
                                style={{ overflowY: "hidden" }}
                                content={(projectBoardStore.SlideModalVisible &&
                                    <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@301s60`} spinning={prjTaskCardStore.loading} style={{ height: "100%" }}>
                                        <TaskCard ecId={`${this && this.props && this.props.ecId || ''}_TaskCard@mmdbpb`} callBack={() =>{
                                            projectBoardStore.prjTaskCardStore.getTaskSubList();
                                            projectBoardStore.prjCardStore.getPrjTaskList();
                                            projectBoardStore.getKanbanView();}} boardStore={projectBoardStore} taskCardStore={prjTaskCardStore} taskid={projectBoardStore.taskid} isNow={projectBoardStore.isNow} />
                                    </Spin>
                                )}
                                onClose={() => projectBoardStore.showSlideModal(false)}
                                onAnimationEnd={() => { }} />

                        </div>
                    </WeaRightMenu>
                </div>
            )
        } else {
            return (<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@0mqf4u`} >
                <div style={{ color: '#000' }}>
                    {getLabel(2012, "对不起，您暂时没有权限！")}
                </div>
            </WeaAlertPage>
            )
        }
    }

    onChange=(v)=>{
        const { projectBoardStore } = this.props;
        const { prjCardStore} = projectBoardStore;
         if(v=='2'){
             prjCardStore.setIsBatchEdit(0);
         }
         projectBoardStore.tabsStore.onChange(v);
        }

    getButtons() {
        const { projectBoardStore } = this.props;
        const { prjCardStore, prjid,title, tabsStore } = projectBoardStore;
        const { rightMenu, form, selectTabKey, taskInfoStore, addProjectStore, shareTableStore, approveplanstatus, status } = prjCardStore;
        let btnArr = [];
        let { selectedRowKeys } = shareTableStore;
        const { saveDefaultInfo } = this.props.prjImportStore;

        const key = tabsStore.activeKey
        const tabDatas1 = toJS(tabsStore.tabDatas);

        rightMenu && rightMenu.length > 0 && rightMenu.map(m => {
            let disabled = false;
            if (tabDatas1) {
                for (let i = 0; i < tabDatas1.length; i++) {
                    if (tabDatas1[i].shortname == "stageset" && tabDatas1[i].key == key && prjCardStore.stageInfo.selectedRowKeys.length == 0) {//项目卡片
                        if (m.type == "BTN_COPY" || m.type == "BTN_DELETE") {
                            disabled = true;
                        }
                    }
                    if (tabDatas1[i].shortname == "prjshare" && tabDatas1[i].key == key && selectedRowKeys.length == 0) {//项目卡片
                        if (m.type == "BTN_COPY" || m.type == "BTN_DELETE") {
                            disabled = true;
                        }
                    }

                    if (tabDatas1[i].shortname == "tasklist" && tabDatas1[i].key == key && approveplanstatus == true) {//项目卡片
                        if (m.type == "BTN_DOSUBMIT") {
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && taskInfoStore.selectedRowKeys.length == 0){
                        if(m.type == "BTN_DELETEBATCH"){
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && taskInfoStore.selectedRowKeys.length == 0){
                        if(m.type == "BTN_SUBMITEDIT"){
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && status == '-1'){
                        if(m.type == "BTN_BREAKDOWN"){
                            disabled = true;
                        }
                    }
                }
            }
            m.isTop == '1' && btnArr.length < 4 && btnArr.push(
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@gjyvqc@${m.type}`} type="primary"
                    disabled={disabled}
                    onClick={() => {

                        if (tabDatas1) {
                            for (let i = 0; i < tabDatas1.length; i++) {
                                if (tabDatas1[i].shortname == "prjinfo" && tabDatas1[i].key == key) {//项目卡片
                                    if (m.type == "BTN_EDIT") { //编辑
                                        prjCardStore.getPrjInfo({ viewtype: 'edit', prjid: prjid });
                                    } else if (m.type == "BTN_SAVE") {  //保存
                                        prjCardStore.savePrjInfo({ prjid: prjid }, projectBoardStore);
                                    } else if (m.type == "BTN_DELETE") {  //删除
                                        prjCardStore.delPrjInfo({ method: "del", prjid: prjid, from: "mymanagerproject" }, projectBoardStore);
                                    }
                                } else if (tabDatas1[i].shortname == "tasklist" && tabDatas1[i].key == key) { //任务列表
                                    if (m.type == "BTN_ADDTASK") {  //添加任务
                                        taskInfoStore.handleDialog(true, "add", '', { prjid: prjid, parentid: "" });
                                    } else if (m.type == 'BTN_IMPTASK') { //任务导入
                                        this.setState({importVisible:true});
                                        saveDefaultInfo(prjid,title);
                                    } else if (m.type == 'BTN_EDIT') { //编辑
                                        prjCardStore.showEditTaskModal(true);
                                    } else if (m.type == 'BTN_DOSUBMIT') { //提交执行
                                        Modal.confirm({
                                            title: getLabel(15172, "系统提示"),
                                            content: getLabel(83919, "你确定要提交执行吗？"),
                                            onOk() {
                                                prjCardStore.doPlanOpt_task({ method: 'approveplan', prjid: prjid }, projectBoardStore);
                                            },
                                            onCancel() { },
                                        });
                                    } else if (m.type == 'BTN_APPSUBMIT') { //提交执行(审批)
                                        Modal.confirm({
                                            title: getLabel(15172, "系统提示"),
                                            content: getLabel(83921, "你确定要提交审批吗？"),
                                            onOk() {
                                                prjCardStore.doPlanOpt_task({ method: 'submitplan', prjid: prjid }, projectBoardStore);
                                            },
                                            onCancel() { },
                                        });
                                    } else if (m.type == "BTN_DELETEBATCH" ){   //批量删除
                                        prjCardStore.delTaskBatch("delbatch");
                                    } else if(m.type == "BTN_EDITBATCH" ){   //批量编辑
                                        prjCardStore.setIsBatchEdit(1);
                                        prjCardStore.getPrjTaskList();
                                        prjCardStore.resetTaskInfoStore();
                                    } else if(m.type == "BTN_BACK" ){   //返回
                                        prjCardStore.setIsBatchEdit(0);
                                        prjCardStore.getPrjTaskList();
                                        prjCardStore.resetTaskInfoStore();
                                    } else if(m.type == "BTN_SUBMITEDIT" ){   //提交编辑
                                        taskBatchEditDialogStore.setVisible(true);
                                    } else if(m.type == "BTN_BREAKDOWN" ){   //任务分解
                                        prjCardStore.triggerBreakDownWF();
                                    }
                                    //  else if (m.type == 'BTN_SENDMESSAGE') { //龙烟二次开发
                                    //     Modal.confirm({
                                    //         title: getLabel(15172, "系统提示"),
                                    //         content:  "你确定要发送通知吗？",
                                    //         onOk() {
                                    //             prjCardStore.sendMsg({prjid: prjid });
                                    //         },
                                    //         onCancel() { },
                                    //     });
                                    // }
                                } else if (tabDatas1[i].shortname == "childprj" && tabDatas1[i].key == key) {//子项目
                                    if (m.type == "BTN_NEWPRJSUB") { //新建子项目
                                        addProjectStore.handleShareDialog(true, { viewtype: 'add', prjid: prjid });
                                    }
                                } else if (tabDatas1[i].shortname == "prjshare" && tabDatas1[i].key == key) {//共享设置
                                    if (m.type == "BTN_APPEND") {  //tianjia
                                        prjCardStore.showAddShareModal(true);
                                    } else if (m.type == 'BTN_DELETEBATCH') { //批量删除
                                        // let { selectedRowKeys } = shareTableStore;
                                        prjCardStore.delBatchShare(`${toJS(selectedRowKeys)}`);
                                    }
                                } else if (tabDatas1[i].shortname == "stageset" && tabDatas1[i].key == key) {  //阶段
                                    if (m.type == 'BTN_ADD_SHARE') { //新增
                                        this.refs.StageList.tableEdit.refs.edit.doAdd()
                                    } else if (m.type == "BTN_DELETE") {  //删除
                                        this.refs.StageList.tableEdit.refs.edit.doDelete()
                                    } else if (m.type == "BTN_COPY") {  //复制
                                        this.refs.StageList.tableEdit.refs.edit.doCopy()
                                    } else if (m.type == "BTN_SUBMIT") {  //保存
                                        const checkProps = this.refs.StageList.tableEdit.refs.edit.doRequiredCheck();
                                        prjCardStore.saveStageSet(checkProps, prjid);
                                    }
                                }
                            }
                        }
                    }}>
                    {m.menuName}
                </Button>
            );
        });
        return btnArr;
    }

    getRightMenu = () => {
        const { projectBoardStore } = this.props;
        const { prjCardStore, tabsStore } = projectBoardStore;
        let btnArr = [];
        const { rightMenu,  taskInfoStore,  approveplanstatus, isApprove, status } = prjCardStore;

        const key = tabsStore.activeKey
        const tabDatas1 = toJS(tabsStore.tabDatas);

        rightMenu && rightMenu.length > 0 && rightMenu.map(m => {
            let disabled = false;
            let { selectedRowKeys } = prjCardStore.shareTableStore;
            if (tabDatas1) {
                for (let i = 0; i < tabDatas1.length; i++) {
                    if (tabDatas1[i].shortname == "stageset" && tabDatas1[i].key == key && prjCardStore.stageInfo.selectedRowKeys.length == 0) {//项目卡片
                        if (m.type == "BTN_COPY" || m.type == "BTN_DELETE") {
                            disabled = true;
                        }
                    }
                    if (tabDatas1[i].shortname == "prjshare" && tabDatas1[i].key == key && selectedRowKeys.length == 0) {//项目卡片
                        if (m.type == "BTN_COPY" || m.type == "BTN_DELETE") {
                            disabled = true;
                        }
                    }

                    if (tabDatas1[i].shortname == "tasklist" && tabDatas1[i].key == key && approveplanstatus == true) {//项目卡片
                        if (m.type == "BTN_DOSUBMIT") {
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && taskInfoStore.selectedRowKeys.length == 0){
                        if(m.type == "BTN_DELETEBATCH"){
                            disabled = true;
                        }
                    }
                    
                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && taskInfoStore.selectedRowKeys.length == 0){
                        if(m.type == "BTN_SUBMITEDIT"){
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "prjinfo" && tabDatas1[i].key == key && isApprove){
                        if(m.menuIcon == "icon-coms-Approval"){
                            disabled = true;
                        }
                    }

                    if(tabDatas1[i].shortname  == "tasklist" && tabDatas1[i].key == key && status == '-1'){
                        if(m.type == "BTN_BREAKDOWN"){
                            disabled = true;
                        }
                    }
                }
            }
            btnArr.push({
                icon: <i className={m.menuIcon} />,
                content: m.menuName,
                disabled: disabled
            })
        });
        return btnArr
    }

    onRightMenuClick(keys) {
        let that = this;
        const { projectBoardStore } = this.props;
        const { prjCardStore, prjid,title, tabsStore } = projectBoardStore;
        const { rightMenu, taskInfoStore, addProjectStore, shareTableStore, relateListStore } = prjCardStore;
        const selectTabKey = projectBoardStore.tabsStore.activeKey;
        const { saveDefaultInfo } = this.props.prjImportStore;
        const key = tabsStore.activeKey
        const tabDatas1 = toJS(tabsStore.tabDatas);

        rightMenu && rightMenu.length > 0 && rightMenu.map((m, i) => {
            if (Number(keys) == i) {
                if (tabDatas1) {
                    for (let i = 0; i < tabDatas1.length; i++) {
                        if (tabDatas1[i].shortname == "prjinfo" && tabDatas1[i].key == key) {//项目卡片
                            let fn = m.menuFun.indexOf('this') >= 0 ? `${m.menuFun.split('this')[0]})` : m.menuFun;
                            if (fn != "") {
                                fn = fn.substring(0, fn.indexOf('('));
                                if ('onNormal' == fn) {   //正常
                                    prjCardStore.doPlanOpt({ method: 'normal', prjid: prjid }, projectBoardStore);
                                } else if ('onOver' == fn) {   //延期
                                    prjCardStore.doPlanOpt({ method: 'delay', prjid: prjid }, projectBoardStore);
                                } else if ('onFinish' == fn) {   //完成
                                    prjCardStore.doPlanOpt({ method: 'complete', prjid: prjid }, projectBoardStore);
                                } else if ('onFrozen' == fn) {   //冻结
                                    prjCardStore.doPlanOpt({ method: 'freeze', prjid: prjid }, projectBoardStore);
                                } else if ('onToggleStatus' == fn) {
                                    prjCardStore.doPlanOpt({ method: 'togglestatus', prjid: prjid, statusid: m.params }, projectBoardStore);
                                }
                            } else {
                                if (m.type == "BTN_EDIT") { //编辑
                                    prjCardStore.getPrjInfo({ viewtype: 'edit', prjid: prjid });
                                } else if (m.type == "BTN_SAVE") {  //保存
                                    prjCardStore.savePrjInfo({ prjid: prjid }, projectBoardStore);
                                } else if (m.type == "BTN_NEWREQ") {  //新建流程
                                    window.open("/spa/workflow/static/index.html#/main/workflow/add?prjid=" + prjid, "_blank");
                                } else if (m.type == "BTN_NEWDOC") {  //新建文档
                                    window.open("/spa/document/static/index.html#/main/document/add?moudleFrom=prj&prjid=" + prjid, "_blank");
                                } else if (m.type == "BTN_NEWRQ") {  //新建日程
                                    this.setState({ workPlanVisible: true })
                                } else if (m.type == "BTN_NEWMT") {  //新建会议
                                    window.open("/spa/meeting/static/index.html#/main/meeting/dialogsingle?type=create&projectid=" + prjid, "_blank");
                                } else if (m.type == "BTN_SAVETEMPLET") {  //另存为模板
                                    prjCardStore.setVisiable(true);
                                } else if (m.type == "BTN_BACK") { //返回
                                    prjCardStore.getPrjInfo({ viewtype: 'view', prjid: prjid });
                                } else if (m.type == "BTN_LOG") {
                                    this.refs.projectLogDialog.setVisible(true);
                                    prjCardStore.getPrjLogList({ prjid: prjid });
                                } else if (m.type == "BTN_DELETE") {
                                    prjCardStore.delPrjInfo({ method: "del", prjid: prjid, from: "mymanagerproject" }, projectBoardStore);
                                }

                            }
                        } else if (tabDatas1[i].shortname == "tasklist" && tabDatas1[i].key == key) {//任务列表
                            if (m.type == "BTN_ADDTASK") {  //添加任务
                                taskInfoStore.handleDialog(true, "add", '', { prjid: prjid, parentid: "" });
                            } else if (m.type == 'BTN_IMPTASK') { //任务导入
                                this.setState({importVisible:true});
                                saveDefaultInfo(prjid,title);
                            }  else if (m.type == 'BTN_EDIT') { //编辑
                                prjCardStore.showEditTaskModal(true);
                            } else if (m.type == 'BTN_DOSUBMIT') { //提交执行
                                Modal.confirm({
                                    title: getLabel(15172, "系统提示"),
                                    content: getLabel(83919, "你确定要提交执行吗？"),
                                    onOk() {
                                        prjCardStore.doPlanOpt_task({ method: 'approveplan', prjid: prjid }, projectBoardStore);
                                    },
                                    onCancel() { },
                                });
                            } else if (m.type == 'BTN_APPSUBMIT') { //提交执行(审批)
                                Modal.confirm({
                                    title: getLabel(15172, "系统提示"),
                                    content: getLabel(83921, "你确定要提交审批吗？"),
                                    onOk() {
                                        prjCardStore.doPlanOpt_task({ method: 'submitplan', prjid: prjid }, projectBoardStore);
                                    },
                                    onCancel() { },
                                });
                            } else if (m.type == 'BTN_TASKEXPORT') { //导出任务
                                prjCardStore.doTaskExcelExp({ prjid: prjid });
                            } else if (m.type == 'BTN_SAVEPLAN') { //存为计划版本
                                prjCardStore.saveasplan({ method: 'saveasplan', prjid: prjid });
                            } else if (m.type == 'BTN_TASKHISTORY') { //历史版本
                                relateListStore.handleRelateDialog(true, "history", prjid)
                            } else if (m.type == 'BTN_NOTEMEMBER') { //通知成员
                                relateListStore.handleRelateDialog(true, "notice", prjid)
                            } else if (m.type == 'BTN_ONREQUEST') { //相关流程
                                relateListStore.handleRelateDialog(true, "request", prjid)
                            } else if (m.type == 'BTN_ONDOC') { //相关文档
                                relateListStore.handleRelateDialog(true, "doc", prjid)
                            } else if (m.type == 'BTN_ONCOWORK') { //相关协作
                                relateListStore.handleRelateDialog(true, "cowork", prjid)
                            } else if (m.type == 'BTN_LOG') {  //日志
                                relateListStore.handleRelateDialog(true, "log", prjid)
                            } else if (m.type == "BTN_DELETEBATCH" ){   //批量删除
                                prjCardStore.delTaskBatch("delbatch");
                            } else if(m.type == "BTN_EDITBATCH" ){   //批量编辑
                                prjCardStore.setIsBatchEdit(1);
                                prjCardStore.getPrjTaskList();
                                prjCardStore.resetTaskInfoStore();
                            } else if(m.type == "BTN_BACK" ){   //返回
                                prjCardStore.setIsBatchEdit(0);
                                prjCardStore.getPrjTaskList();
                                prjCardStore.resetTaskInfoStore();
                            } else if(m.type == "BTN_SUBMITEDIT" ){   //提交编辑
                                taskBatchEditDialogStore.setVisible(true);
                            } else if(m.type == "BTN_BREAKDOWN" ){   //任务分解
                                prjCardStore.triggerBreakDownWF();
                            }
                        } else if (tabDatas1[i].shortname == "childprj" && tabDatas1[i].key == key) {//子项目
                            if (m.type == "BTN_NEWPRJSUB") { //新建子项目
                                addProjectStore.handleShareDialog(true, { viewtype: 'add', prjid: prjid });
                            }
                        } else if (tabDatas1[i].shortname == "prjshare" && tabDatas1[i].key == key) {//共享设置
                            if (m.type == "BTN_APPEND") {  //tianjia
                                prjCardStore.showAddShareModal(true);
                            } else if (m.type == 'BTN_DELETEBATCH') { //批量删除
                                let { selectedRowKeys } = shareTableStore;
                                prjCardStore.delBatchShare(`${toJS(selectedRowKeys)}`);
                            }
                        } else if (tabDatas1[i].shortname == "stageset" && tabDatas1[i].key == key) {  //阶段
                            if (m.type == 'BTN_ADD_SHARE') { //新增
                                this.refs.StageList.tableEdit.refs.edit.doAdd()
                            } else if (m.type == "BTN_DELETE") {  //删除
                                this.refs.StageList.tableEdit.refs.edit.doDelete()
                            } else if (m.type == "BTN_COPY") {  //复制
                                this.refs.StageList.tableEdit.refs.edit.doCopy()
                            } else if (m.type == "BTN_SUBMIT") {  //保存
                                const checkProps = this.refs.StageList.tableEdit.refs.edit.doRequiredCheck();
                                prjCardStore.saveStageSet(checkProps, prjid);
                            }
                        }
                        if (m.type == "BTN_COLUMN") {  //显示定制
                            prjCardStore.onShowColumn();
                        }
                    }
                }
            }
        });
    }

    
    setWorkPlanVisible = (bool) => {
        this.setState({ workPlanVisible: bool })
    }

    doClose = () => {
        const {prjImportStore} = this.props;
        this.setState({importVisible:!this.state.importVisible});
        prjImportStore.clearStatus();
    }
    getDialogTopButtons() {
        let btns = [];
        const {doImport} = this.props.prjImportStore;
        const { prjCardStore,prjid } = this.props.projectBoardStore;
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@bqi1lz@search`} type="primary"  onClick={() =>  {doImport(prjCardStore.refTaskList)}}>{getLabel(615,"提交")}</Button>);
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@60lhs0@cancel`} type="primary" onClick={() => { this.doClose() }}>{getLabel(309, "关闭")}</Button>);
        return btns;
    }
    getDialogRightMenu(){
        const {doImport} = this.props.prjImportStore;
        const { prjCardStore,prjid } = this.props.projectBoardStore;
        let btnArr = [];
        btnArr.push({
            key: '1',
            icon: <i className={"icon-coms-Approval"} />,
            content: getLabel(615,"提交"),
            onClick:(key)=>{
                doImport(prjCardStore.refTaskList);
            }  
        });
        return btnArr;
    }
}